package com.atguigu.tingshu.order.mq;

import com.atguigu.tingshu.common.constant.KafkaConstant;
import com.atguigu.tingshu.order.service.OrderInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
@Slf4j
public class OrderReceiver {
    @Autowired
    private OrderInfoService orderInfoService;

    @KafkaListener(topics = KafkaConstant.QUEUE_ORDER_PAY_SUCCESS)
    public void orderPaySuccess(ConsumerRecord<String, String> consumerRecord) {
        String orderNo = consumerRecord.value();
        if (!StringUtils.isEmpty(orderNo)) {
            orderInfoService.orderPaySuccess(orderNo);
            log.info("更改支付状态并保存购买信息成功...orderNo",orderNo);
        }
    }
}
